import get_hwnd;
import get_process_image;
import  find_image;
import cv2;
import time;
import win32api, win32con;
energy = 100
def startHardWork(hwnd) :
    for i in range(0, int(energy/2)):
        long_position = win32api.MAKELONG(1105, 412)#模拟鼠标指针 传送到指定坐标
        win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)#模拟鼠标按下
        win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)#模拟鼠标弹起
        time.sleep(0.1)
        win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, 87,0) #Tab
        win32api.PostMessage(hwnd, win32con.WM_KEYUP, 87,0) #Realize the Ctrl button
        if i % 10 == 0:
            if i % 50 == 0:
                time.sleep(0.1)
                win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, 51, 0)
                win32api.PostMessage(hwnd, win32con.WM_KEYUP, 51, 0)
            else :
                time.sleep(0.1)
                win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, 50, 0)
                win32api.PostMessage(hwnd, win32con.WM_KEYUP, 50, 0)
    poss = [[73, 118],[67, 204],[73, 289],[73, 368],[491, 118],[491, 204],[491, 289],[491, 368]]
    for pos in poss:
        long_position = win32api.MAKELONG(pos[0], pos[1])#模拟鼠标指针 传送到指定坐标
        win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)#模拟鼠标按下
        time.sleep(0.1)
        win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)#模拟鼠标弹起
        time.sleep(0.1)
left, right, top, bottom, hwnd = get_hwnd.getRectangle()
while True:
        get_process_image.saveWinImage(hwnd);
        fullPowerImg = cv2.imread("images/full_power" + ".bmp");
        windowImg = cv2.imread("images/img_Winapi.bmp");
        findIcon = find_image.fastFind(windowImg, fullPowerImg);
        if findIcon != -1 and findIcon[0] > 570 and findIcon[0] < 660\
                and findIcon[1] > 530 and findIcon[1] <600:
            startHardWork(hwnd)
        time.sleep(6)
